package com.zhixuan.autoui.core;

import com.tinker.coresdk.manager.ZXSpeechRecognitionManager;
import com.tinker.coresdk.release.iface.SpeechRecognitionTool;
import com.zhixuan.autoui.widget.DialogSpeechRecognition;

import cd.zhixuan.utils.LogTools;

/**
 * @author: HuZC
 * @Description:
 * @Date: 2022/1/10
 */
public class SpeechModule extends BaseModule {


    private static class Holder {
        static final SpeechModule INSTANCE = new SpeechModule();
    }

    public static SpeechModule getInstance() {
        return Holder.INSTANCE;
    }

    private SpeechModule() {
    }

    @Override
    public void init() {
        DialogSpeechRecognition.getInstance();
        ZXSpeechRecognitionManager.getInstance().setTool(speechRecognitionTool);
    }

    private final SpeechRecognitionTool speechRecognitionTool = new SpeechRecognitionTool() {
        @Override
        public void onSpeechRecognitionRecoderStateChange(int state) {
            LogTools.d("state=" + state);

        }

        @Override
        public void onSpeechRecognitionUITypeChange(int uiType) {
            LogTools.d("uiType=" + uiType);

        }

        @Override
        public void onSpeechRecognitionAsrRawText(String json) {
            LogTools.d(json);

        }

        @Override
        public void onSpeechRecognitionAsrControlCommand(String json) {
            LogTools.d(json);

        }

        @Override
        public void onSpeechRecognitionTtsState(int ttsState) {
            LogTools.d("ttsState=" + ttsState);

        }

        @Override
        public void onRequestTtsPlayResult(String text, int repeatCount, String requesterPkgName, int resultCode) {
            LogTools.d("text=" + text + " repeatCount=" + repeatCount + " requesterPkgName=" + requesterPkgName + " resultCode=" + resultCode);

        }

        @Override
        public void onSpeechRecognitionDialogShow() {
            DialogSpeechRecognition.getInstance().showOnUiThread();
        }

        @Override
        public void onSpeechRecognitionDialogHide() {
            DialogSpeechRecognition.getInstance().dismiss();
        }

        @Override
        public void onSpeechRecognitionDialogText(String text) {
            LogTools.d("text=" + text);
            DialogSpeechRecognition.getInstance().setRecognitionText(text);
        }
    };

    @Override
    public void release() {
        ZXSpeechRecognitionManager.getInstance().removeTool(speechRecognitionTool);
    }
}
